package com.wfm.leetcode.editor.cn;

/**
 * 搜索二维矩阵
 * 2025-02-26 14:57:14
 * 从左到右从上到下一直递增
 */
class SearchA2dMatrix {

    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
        // 把二维摊成一维
        public boolean searchMatrix(int[][] matrix, int target) {
            int m = matrix.length, n = matrix[0].length;
            int low = 0, high = m * n - 1;
            while (low <= high) {
                int mid = (high - low) / 2 + low;
                int x = matrix[mid / n][mid % n];
                if (x < target) {
                    low = mid + 1;
                } else if (x > target) {
                    high = mid - 1;
                } else {
                    return true;
                }
            }
            return false;
        }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) {
        Solution solution = new SearchA2dMatrix().new Solution();
        
    }
}